/*******************************************************************************
 * Copyright (c) 2009 Markus Knittig and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Markus Knittig - initial API and implementation
 *******************************************************************************/
package com.googlecode.mylyn.ui;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.mylyn.tasks.ui.TasksUi;
import org.eclipse.mylyn.tasks.ui.TasksUiImages;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

import com.googlecode.mylyn.core.GoogleCodeCorePlugin;

/**
 * The activator class controls the plug-in life cycle
 */
public class GoogleCodeUiPlugin extends AbstractUIPlugin {

    public static final String PLUGIN_ID = "com.googlecode.mylyn.ui";

    private static GoogleCodeUiPlugin plugin;

    @Override
    public void start(BundleContext context) throws Exception {
        super.start(context);
        plugin = this;

        TasksUi.getRepositoryManager().addListener(GoogleCodeCorePlugin.getDefault().getConnector().getClientManager());
    }

    @Override
    public void stop(BundleContext context) throws Exception {
        plugin = null;
        super.stop(context);
    }

    @Override
    protected void initializeImageRegistry(ImageRegistry registry) {
        super.initializeImageRegistry(registry);
        registry.put("" + TasksUiImages.REPOSITORY_SMALL.hashCode(), TasksUiImages.REPOSITORY_SMALL);
    }

    public Image getImage(ImageDescriptor descriptor) {
        return getImageRegistry().get("" + descriptor.hashCode());
    }

    /**
     * Returns the shared instance
     */
    public static GoogleCodeUiPlugin getDefault() {
        return plugin;
    }

}
